package com.danciyixue.boot.dcyx.controller;

import com.danciyixue.boot.dcyx.service.UserWordStatusService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.danciyixue.boot.dcyx.model.form.UserWordStatusForm;
import com.danciyixue.boot.dcyx.model.query.UserWordStatusQuery;
import com.danciyixue.boot.dcyx.model.vo.UserWordStatusVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.danciyixue.boot.common.result.PageResult;
import com.danciyixue.boot.common.result.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

/**
 * 用户单词学习状态前端控制层
 *
 * @author youlaitech
 * @since 2025-06-24 15:50
 */
@Tag(name = "用户单词学习状态接口")
@RestController
@RequestMapping("/api/v1/user-word-status")
@RequiredArgsConstructor
public class UserWordStatusController  {

    private final UserWordStatusService userWordStatusService;

    @Operation(summary = "用户单词学习状态分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('dcyx:user-word-status:query')")
    public PageResult<UserWordStatusVO> getUserWordStatusPage(UserWordStatusQuery queryParams ) {
        IPage<UserWordStatusVO> result = userWordStatusService.getUserWordStatusPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增用户单词学习状态")
    @PostMapping
    @PreAuthorize("@ss.hasPerm('dcyx:user-word-status:add')")
    public Result<Void> saveUserWordStatus(@RequestBody @Valid UserWordStatusForm formData ) {
        boolean result = userWordStatusService.saveUserWordStatus(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取用户单词学习状态表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('dcyx:user-word-status:edit')")
    public Result<UserWordStatusForm> getUserWordStatusForm(
        @Parameter(description = "用户单词学习状态ID") @PathVariable Long id
    ) {
        UserWordStatusForm formData = userWordStatusService.getUserWordStatusFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改用户单词学习状态")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('dcyx:user-word-status:edit')")
    public Result<Void> updateUserWordStatus(
            @Parameter(description = "用户单词学习状态ID") @PathVariable Long id,
            @RequestBody @Validated UserWordStatusForm formData
    ) {
        boolean result = userWordStatusService.updateUserWordStatus(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除用户单词学习状态")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('dcyx:user-word-status:delete')")
    public Result<Void> deleteUserWordStatuss(
        @Parameter(description = "用户单词学习状态ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = userWordStatusService.deleteUserWordStatuss(ids);
        return Result.judge(result);
    }
}
